/**
 * 管理页面
 */
package net.youpo.Market.UI.Manager;

import net.youpo.Market.R;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class ManagerActivity extends TabActivity {
	private TabHost m_tabHost;
	private LayoutInflater mLayoutInflater;
	private Class mTopTabClassArray[] = { DownloadManagerActivity.class,
			AppManagerActivity.class, AppFavoritesActivity.class};
	private String mTopTabTextArray[] = { "下载管理", "软件管理", "我的收藏" };
	private View[] mTabViewArr = new View[mTopTabClassArray.length];// 选中的那个View

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.homepage_activity);
		init();
	}

	private void init() {
		m_tabHost = getTabHost();
		//h3c modifyed start :可以在xml中统一设置
//		m_tabHost.getTabWidget().setBackgroundResource(R.drawable.manager_tab_background);
		//h3c modifyed end
		mLayoutInflater = LayoutInflater.from(this);

		int count = mTopTabClassArray.length;
		for (int i = 0; i < count; i++) {
			TabSpec tabSpec = m_tabHost.newTabSpec(mTopTabTextArray[i])
					.setIndicator(getTabItemView(i))
					.setContent(getTabItemIntent(i));
			m_tabHost.addTab(tabSpec);
		}
		
			m_tabHost.setOnTabChangedListener(new OnTabChangeListener() {
				@Override
				public void onTabChanged(String tabId) {
				}
			});
		
	}

	private View getTabItemView(int index) {
		View view = mLayoutInflater.inflate(R.layout.tab_item_view, null);
		TextView textView = (TextView) view.findViewById(R.id.textview);
		textView.setText(mTopTabTextArray[index]);
		switch(index){
		case 0:
			view.setBackgroundResource(R.drawable.manager_tab_download_selector);
			break;
		case 1:
			view.setBackgroundResource(R.drawable.manager_tab_app_selector);
			break;
		case 2:
			view.setBackgroundResource(R.drawable.manager_tab_favorites_selector);
			break;
		}
		mTabViewArr[index] = view;
		return view;
	}

	private Intent getTabItemIntent(int index) {
		Intent intent = new Intent(this, mTopTabClassArray[index]);
		return intent;
	}
}
